package com.mudalov.rec.dao.hibernate.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @author mudalov
 * 
 */
public class HibernateUtil {

	private static SessionFactory sessionFactory;

	private static Configuration configuration;

	static {
		try {
			configuration = new Configuration().configure();
			sessionFactory = configuration.buildSessionFactory();
		} catch (Throwable ex) {
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static Configuration getConfiguration() {
		return configuration;
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public static void shutdown() {
		sessionFactory.close();
	}

	public static void buildSessionFactory() {
		sessionFactory = configuration.buildSessionFactory();
	}
}
